/*
 * @Description:字符缓冲流
 * 
 * @Author: rendc
 * 
 * @Date: 2025-08-22 09:41:33
 * 
 * @LastEditors: rendc
 * 
 * @LastEditTime: 2025-08-22 09:57:39
 */

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.nio.Buffer;

public class TestBufferedChar {

  public static void main(String[] args) throws Exception {
    // 1. 创建基础流 - 增强
    BufferedReader br = new BufferedReader(new FileReader("readme"));
    BufferedWriter bw = new BufferedWriter(new FileWriter("readme1"));
    // 2. 增强流的读写
    String line;
    // 逐行读取
    while ((line = br.readLine()) != null) {
      // 输出数据
      System.out.println("line:" + line);

      // // true代表有下一行 false马上要读完了
      // if (br.ready()) {
      // // 写入数据 手动拼接换行
      // bw.write(line + "\n");
      // } else {
      // bw.write(line);
      // }

      bw.write(line);
      if (br.ready()) {
        // 写入新的一行
        bw.newLine();
      }

    }
    // 关闭资源
    bw.close();
    br.close();
  }
}